package com.wuyou.designPatterns.visiotor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Description
 * @Author 无忧
 * @Date 2024/10/11 21:20
 */
public class Directory extends Entry{

    private String name;
    private List<Entry> dir = new ArrayList<>();

    public Directory(String name){
        this.name = name;
    }


    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public int getSize() {
        int size = 0;
        Iterator<Entry> iterator = this.dir.iterator();
        while (iterator.hasNext()){
            Entry next = iterator.next();
            size += next.getSize();
        }
        return size;
    }

    public Entry add(Entry entry){
        dir.add(entry);
        return this;
    }

    public Iterator<Entry> iterator(){
        return dir.iterator();
    }

    public void accept(Visitor visitor){
        visitor.visit(this);
    }
}
